	//立即备份
	function backup(){
		var formData = new FormData($( "#export-form" )[0]);
		$(".backup").parent().children().prop('disabled', true);
		$(".backup").html("正在发送备份请求...");
		 $.ajax({    
	          url:  "/administrative/Data/backup",    
	          type: 'POST',    
	          data: formData,    
	          async: false,    
	          cache: false,    
	          contentType: false,    
	          processData: false,
	          dataType : 'json',
	          success: function (data) {
	        	 if(data.code == '1'){ 
					$(".backup").text(data.msg + "开始备份，请不要关闭本页面！");
					tables = data.data.tables;
					StartTheBackup(data.data.tab);
					window.onbeforeunload = function () {
					    return "正在备份数据库，请不要关闭！";
					};
	        	 }else{
	        		 top.layer.msg(data.msg,{icon:2,time:2000,shade: 0.1,});
	        		 $(".backup").html("立即备份");
                     setTimeout(function () {
                    	 $(".backup").parent().children().prop('disabled', false);
                     }, 1500);
	        	 }
	          },error: function (data) {    
	        	top.layer.msg('数据异常', {icon: 2,time: 2000});
				return false; 
	          }    
	     });  
	}
	
	
	
	//开始备份
	function StartTheBackup(tab, status){
		 status && showmsg(tab.id, "开始备份...(0%)");
		 	$.get("/administrative/Data/backup",tab,function(data){
           // $.get($form.attr("action"), tab, function (data) {
                if (data.code) {
                    showmsg(tab.id, data.msg);
                    if (!$.isPlainObject(data.data.tab)) {
                    	$(".backup").parent().children().prop('disabled', false);
                        $(".backup").html("备份完成，点击重新备份");
                        window.onbeforeunload = function () {
                            return null;
                        };
                        return;
                    }
                    StartTheBackup(data.data.tab, tab.id != data.data.tab.id);
                } else {
                    layer.msg(data.msg, 0);
                    $(".backup").html("立即备份");
                    setTimeout(function () {
                    	$(".backup").parent().children().prop('disabled', false);
                    }, 1500);
                }
            });
	}
	
	
	function showmsg(id, msg) {
		$("#export-form").find("input[value=" + tables[id] + "]").closest("tr").find("#info").html(msg);
		
	};
	
	//优化表 单条
	
	function optimizeOne(tablename,obj){
		$.post("/administrative/Data/optimize",{ids:tablename},function(data){
			if(data.code == '1'){
				$(obj).parents('tr').find('#info').text('优化完成');
				top.layer.msg(data.msg, {icon: 1,time: 2000});
			}else{
				top.layer.msg(data.msg, {icon: 2,time: 2000});
			}
			
		},'json');
	}
	
	//优化所有
	$(".optimization").click(function(){
		var formData = new FormData($( "#export-form" )[0]);
		$(".optimization").parent().children().prop('disabled', true);
		$.ajax({
			  url:  "/administrative/Data/optimize",    
	          type: 'POST',    
	          data: formData,    
	          async: false,    
	          cache: false,    
	          contentType: false,    
	          processData: false,
	          dataType : 'json',
	          success: function (data) {
	        	 if(data.code == '1'){
	        		 $(".optimization").parent().children().prop('disabled', false);				        		 
	        		 top.layer.msg(data.msg, {icon: 1,time: 2000});
	        	 }else{
	        		 top.layer.msg(data.msg, {icon: 2,time: 2000});
	        		 $(".optimization").parent().children().prop('disabled', false);
	        	 }
	          },error: function (data) {    
	        	top.layer.msg('数据异常', {icon: 2,time: 2000});
	        	$(".optimization").parent().children().prop('disabled', false);
				return false; 
	          }    
		});
	})
	
	//修复表 单条
	
	function repairOne(tablename,obj){
		$.post("/administrative/Data/repair",{ids:tablename},function(data){
			if(data.code == '1'){
				$(obj).parents('tr').find('#info').text('修复完成'); 
				top.layer.msg(data.msg, {icon: 1,time: 2000});
			}else{
				top.layer.msg(data.msg, {icon: 2,time: 2000});
			}
		},'json');
	}
	
	
	
	//修复所有
	$(".repair").click(function(){
		var formData = new FormData($( "#export-form" )[0]);
		$(".repair").parent().children().prop('disabled', true);
		$.ajax({
			  url:  "/administrative/Data/repair",    
	          type: 'POST',    
	          data: formData,    
	          async: false,    
	          cache: false,    
	          contentType: false,    
	          processData: false,
	          dataType : 'json',
	          success: function (data) {
	        	 if(data.code == '1'){
	        		 $(".repair").parent().children().prop('disabled', false);				        		 
	        		 top.layer.msg(data.msg, {icon: 1,time: 2000});
	        	 }else{
	        		 top.layer.msg(data.msg, {icon: 2,time: 2000});
	        		 $(".repair").parent().children().prop('disabled', false);
	        	 }
	          },error: function (data) {    
	        	top.layer.msg('数据异常', {icon: 2,time: 2000});
	        	$(".repair").parent().children().prop('disabled', false);
				return false; 
	          }    
		});
	})
	
	
	
	

	
